<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{ background: linear-gradient(#23252d 3%, #2a343f 97%);height:100%;  }
			.top { padding-top:110px; text-align:center; }
			.top img { margin:0 auto; width:70px; }
			.top b {display:block; font-size: 18px; font-weight: 500; color:#fff; line-height: 30px; padding-top: 7px;}
			.top p {display:block; font-size: 14px; font-weight: 400; color: #e2e3e6; line-height: 25px; }
			.footer { position: fixed; left: 0; right: 0; bottom: 45px; display:flex; }
			.footer div { width:50%; border:0px red solid; text-align: center;}
			.footer img { width:50px; margin:0 auto; }
			.footer div p { font-size:12px; color:#fff; line-height:35px;}
			.display-none{ display:none; }
			.display-none{ display:none; }
			.text-center { text-align: center !important; }
			
		</style>
	</head>
	<body>
		<div class="top">
			<img src="../../image/defaultimg.png" id="avatar">
			<b id="nickname">--</b>
			<p id="status">正在邀请您语音通话</p>
		</div>
		<div class="footer">
			
			<div tapmode onclick="hangup();">
				<img src="../../image/refuse.png" />
				<p>拒绝</p>
			</div>
			<div tapmode onclick="fnaccept();">
				<img src="../../image/accept.png" />
				<p>接受</p>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var rong;
		var dfuid,dfnickname,dfavatar,mediaType,callId;
		apiready = function() {
			api.parseTapmode();
			api.bringFrameToFront({
				from: api.frameName
			});
			rong = api.require('rongCloud2');
			dfuid = api.pageParam.dfuid;
			dfnickname = api.pageParam.dfnickname;
			dfavatar = api.pageParam.dfavatar;
			mediaType = api.pageParam.mediaType;
			callId = api.pageParam.callId;
			if(dfavatar != '') {
				$api.byId('avatar').src = dfavatar;
			}
			$api.text($api.byId('nickname'),dfnickname);
			var status = '对方正在邀请您语音通话';
			if(mediaType == 'video') {
				status = '对方正在邀请您视频通话';
			}
			$api.text($api.byId('status'),status);
			
			//playMP3();
		}
		function closeframe() {
			api.closeFrame({
				name: api.frameName
			});
		}
		function playMP3() {
			api.startPlay({
				path: 'widget://res/wxring.mp3'
			}, function(ret, err) {
				if (ret) {
					playMP3();
				} else {
					//alert(JSON.stringify(err));
				}
			});
		}
		function fnaccept() {
			//alert(mediaType+'?'+callId);
			var params = {
				callId: callId
			}
			if (api.systemType == "ios") {
				params = {
					mediaType: mediaType
				}
				
			}
			rong.accept(params);
		}
		function hangup() {
			//挂断
			rong.hangup();
			api.stopPlay();
			api.startPlay({
				path: 'widget://res/dong.wav'
			}, function(ret, err) {
				if (ret) {
					setTimeout(function(){
						closeframe();
					}, 1000);
					
				} else {
					//alert(JSON.stringify(err));
				}
			});
		}
	</script>
</html>